package com.example.boot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.LogAnno;
import com.example.common.Result;
import com.example.common.enums.LogType;
import com.example.pojo.entity.Contract;
import com.example.pojo.entity.Cost;
import com.example.pojo.entity.Device;
import com.example.pojo.utils.ApprocalPageResult;
import com.example.service.CostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 成本接口
 **/
@RestController
@RequestMapping("/cost")
@Api(tags = "成本费用接口")
public class CostController {

    @Resource
    private CostService costService;
    @ApiOperation("新增成本信息")
    @LogAnno(title = "成本管理", type = LogType.ADD)
    @PostMapping("/add")
    public Result add(@ApiParam("成本信息") @RequestBody Cost cost) {
        costService.add(cost);
        return Result.success();
    }

    @ApiOperation("通过Id获取成本费用信息")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Cost cost = costService.getById(id);
        return Result.success(cost);
    }
    @ApiOperation("分页展示成本费用信息列表")
    @GetMapping("/selectPage")
    public Result selectPage(String name,
            @ApiParam("当前页数") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("页面数据大小") @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<Cost> page = costService.selectPage(name,pageNum, pageSize);

        return Result.success(page);
    }
    @ApiOperation("根据ID批量删除成本费用信息")
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        costService.deleteBatch(ids);
        return Result.success();
    }
    @ApiOperation("通过Id删除成本费用信息")
    @LogAnno(title = "成本管理", type = LogType.DELETE)
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        costService.deleteById(id);
        return Result.success();
    }

    @ApiOperation("更新成本费用信息")
    @LogAnno(title = "成本管理", type = LogType.UPDATE)
    @PutMapping("/update")
    public Result update(@RequestBody Cost cost) {
        costService.update(cost);
        return Result.success();
    }


}
